package top.xbaoziplus.company.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.xbaoziplus.company.vo.ApplyVo;
import top.xbaoziplus.company.common.Result;
import top.xbaoziplus.company.empty.UserInfo;
import top.xbaoziplus.company.service.ApplyService;

import javax.servlet.http.HttpSession;

/**
 * @author xBaozi
 * @version 1.0
 * @classname ApplyController
 * @description 申请表控制器
 * @date 2022/6/29 9:20
 */
@RestController
@RequestMapping("/apply")
@Api(tags = "申请模块")
@Slf4j
public class ApplyController {

    @Autowired
    private ApplyService applyService;

    @ApiOperation("用户提交申请接口")
    @PostMapping("/user/apply")
    public Result apply(@RequestBody @ApiParam("传type类型和reason申请原因和content申请内容") ApplyVo applyVo,
                        HttpSession session) {
        UserInfo info = (UserInfo) session.getAttribute("user");
        applyVo.setJobId(info.getJobId());
        return applyService.addApply(applyVo);
    }

    @ApiOperation("管理员分页展示审核申请列表")
    @PostMapping("/admin/applyList")
    public Result applyList(@RequestBody @ApiParam("状态，当前页码，一页数据数量")
                                    ApplyVo applyVo,
                            HttpSession session) {
        return applyService.applyList(applyVo);
    }

    @ApiOperation("用户获取申请审核列表")
    @PostMapping("/user/applyList")
    public Result userApplyList(@RequestBody @ApiParam("传审核状态过来和申请的类型和当前页码，一页数据数量") ApplyVo applyVo, HttpSession session){
        UserInfo info = (UserInfo) session.getAttribute("user");
        applyVo.setJobId(info.getJobId());
        return applyService.userApplyList(applyVo);
    }
}
